import { Controller, Get, Post, Body, Patch, Param, Delete, Query } from '@nestjs/common';
import { UserRoleService } from './user-role.service';
import { CreateUserRoleDto } from './dto/create-user-role.dto';
import { UpdateUserRoleDto } from './dto/update-user-role.dto';
import { userAddRoleDto } from './dto/user-add-role-dto';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { GetRoleIdByUserIdDto } from './dto/getRoleIdByUserId.dto';


@Controller('system/userRole')
@ApiTags('用户与角色相关')
@ApiBearerAuth()
export class UserRoleController {
    constructor(private readonly userRoleService: UserRoleService) {
    }
    
    @Post()
    create(@Body() createUserRoleDto: CreateUserRoleDto) {
        return this.userRoleService.create(createUserRoleDto);
    }
    
    @Get('getRoleIdByUserId')
    @ApiOperation({ summary: '更具userId查询roleId' })
    getRoleIdByUserId(@Query() dto: GetRoleIdByUserIdDto) {
        return this.userRoleService.getRoleIdByUserId(dto);
    }
    
    @Get()
    findAll() {
        return this.userRoleService.findAll();
    }
    
    @Get(':id')
    findOne(@Param('id') id: string) {
        return this.userRoleService.findOne(+id);
    }
    
    @Patch(':id')
    update(@Param('id') id: string, @Body() updateUserRoleDto: UpdateUserRoleDto) {
        return this.userRoleService.update(+id, updateUserRoleDto);
    }
    
    @Delete(':id')
    remove(@Param('id') id: string) {
        return this.userRoleService.remove(+id);
    }
    
    @Post('userAddRole')
    @ApiOperation({ summary: '用户添加角色' })
    userAddRole(@Body() userAddRoleDto: userAddRoleDto) {
        return this.userRoleService.userAddRole(userAddRoleDto);
    }
}
